#pragma once
#include "../radar.h"
#include "common.h"
#define CAT240RADAR_LOG_TITLE ("$CAT240")
#define VTSRADARSPOKES (1024)
#include "../radar_data_manager.h"
#include "randomsignalemitter.h"
#include <iostream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <thread>
#include <vector>
class cat240_decode : public Radar
{
public:
	cat240_decode(boost::asio::io_service& io_service);
	virtual ~cat240_decode();
    int fangwixian_bh=0;
    int fangwixian_chazhi=0;
	static Cat240state states;
    static RandomSignalEmitter * RandomSignal_;
public:
	virtual bool do_video_processer(const char *data, unsigned int length);
	virtual void do_status_processer(const char *data, unsigned int length, unsigned int radar_key = 0);
	
	virtual void StartOwnProcess();
	void SendCmd(const std::string &data);

private:
	bool check_frame_head(unsigned char*);
	void OnRadarRangeChanged(unsigned int range);
	int Decode(unsigned char*, int);
	void Video_Summary_Message(unsigned char *Data);
	void Video_Message(unsigned char *Data);
	double GetBetween(const Cat240ItemHeader_t &spoke);
private:
	unsigned char m_old_range;

    std::ofstream fileStream;
    std::string fileName;
    void init_appendToFile();
    void close_appendToFile();
    void appendToFile(const std::string& content);

};
